package com.lc.cehui.ui.fragment.home;

import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.google.android.flexbox.FlexDirection;
import com.google.android.flexbox.FlexboxLayoutManager;
import com.google.android.flexbox.JustifyContent;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lc.cehui.R;
import com.lc.cehui.app.AppFragment;
import com.lc.cehui.http.response.CompanyInfoBean;
import com.lc.cehui.http.response.TechnologyShowBean;
import com.lc.cehui.other.IntentKey;
import com.lc.cehui.ui.activity.home.ParticularsActivity;
import com.lc.cehui.util.SPUtil;
import com.lc.cehui.widget.StretchyTextView;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

public class ParticularsInformationFragment extends AppFragment<ParticularsActivity> {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.spread_textview)
    StretchyTextView spreadTextView;
    @BindView(R.id.tv_mobile)
    TextView tvMobile;

    private BaseQuickAdapter adapter;
    List<CompanyInfoBean.DataBean.WelfareBean> dataPopularBeanList = new ArrayList<>();
    private CompanyInfoBean data;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_particularsinformation;
    }

    @Override
    protected void initView() {

        FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(getContext());
        layoutManager.setFlexDirection(FlexDirection.ROW);
        layoutManager.setJustifyContent(JustifyContent.FLEX_START);
        recyclerView.setLayoutManager(layoutManager);
        adapter = new BaseQuickAdapter<CompanyInfoBean.DataBean.WelfareBean, BaseViewHolder>
                (R.layout.item_gongsifuli,dataPopularBeanList) {

            @Override
            protected void convert(BaseViewHolder baseViewHolder,CompanyInfoBean.DataBean.WelfareBean dataBean) {
                baseViewHolder.setText(R.id.tv_name,dataBean.getWelfare());
            }


        };
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() {
        Gson gson = new Gson();
//                将存储的数据转成实体类
        data = gson.fromJson(SPUtil.get(getContext(), IntentKey.TEXT,""), new TypeToken<CompanyInfoBean>() {
        }.getType());
        dataPopularBeanList.addAll(data.getData().getWelfare());
        adapter.setNewData(dataPopularBeanList);
        adapter.notifyDataSetChanged();

        spreadTextView.setMaxLineCount(3);
        spreadTextView.setContent(data.getData().getCompany_des());

        tvMobile.setText(data.getData().getMobile());
    }


}
